const events = require('events');
const util = require('util');
const fs = require('fs');

function Watcher(watchDir, processedDir) {
  this.watchDir = watchDir;
  this.processedDir = processedDir;
}

util.inherits(Watcher, events.EventEmitter);

Watcher.prototype.watch = function () {
  const watcher = this;
  fs.readdir(this.watchDir, function (err, files) {
    if (err) {
      throw err;
    }
    for (const index in files) {
      watcher.emit('process', files[index]);
    }
  });
};

Watcher.prototype.start = function () {
  const watcher = this;
  fs.watchFile(this.watchDir, function () {
    watcher.watch();
  });
};
module.exports = Watcher;
